/*
  学习目标：setState更新过程

*/
import React, { Component } from 'react';

export default class App extends Component {
  state = {
    count: 0,
  };

  handleClick = () => {
    // 💥 setState更新时异步的
    // 💥 setState连续调用对同一个状态更新时, 会产生合并的效果
    // 💥 目的: 减少render执行的次数, 从而减少频繁操作dom
    this.setState({
      count: this.state.count + 1,
    });
    this.setState({
      count: this.state.count + 2,
    });
    this.setState({
      count: this.state.count + 3,
    });

    console.log('this.state.count  ----->  ', this.state.count);
  };

  render() {
    console.log('render  ----->  ');
    const { count } = this.state;
    return (
      <div>
        <h1>{count}</h1>
        <button onClick={this.handleClick}>点我更细</button>
      </div>
    );
  }
}
